﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using ExamSystem.Mdeol;
namespace ExamSystem.DAL
{
    public class TclassDAL
    {
        /// <summary>
        /// 查询班级信息
        /// </summary>
        public List<Tclass> selecttclass()
        {
            List<Tclass> list = new List<Tclass>();
            string sql = "select * from tclass";
            DataSet ds = DBhepter.GetDataSet(sql);
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                int tcId = int.Parse(dr["tcId"].ToString());
                string tcNo = dr["tcNo"].ToString();
                Tclass ts = new Tclass(tcId, tcNo);
                list.Add(ts);
            }
            return list;
        }


        /// <summary>
        /// 添加班级
        /// </summary>
        public int inserttclass(string tcno)
        {
            string sql = "insert into tclass values('"+tcno+"')";
            return DBhepter.ExecuteNonQuery(sql);
        }


        /// <summary>
        /// 根据名称查询是否有数据
        /// </summary>
        public int selecttcno(string tcno)
        {
            string sql = "select * from tclass where tcNo='"+tcno+"'";
            DataSet ds = DBhepter.GetDataSet(sql);
            DataTable dt = ds.Tables[0];
            return dt.Rows.Count;
        }


        /// <summary>
        /// 根据班级编号查询是否有数据
        /// </summary>
        public Tclass selecttcid(int tcid)
        {
            Tclass t =null;
            string sql = "select * from tclass where tcid=" + tcid + "";
            DataSet ds = DBhepter.GetDataSet(sql);
            DataTable dt = ds.Tables[0];
            if(dt.Rows.Count>0)
            {
                DataRow dr = dt.Rows[0];
                int tcId = (int)dr["tcid"];
                string tcno = dr["tcno"].ToString();
                t= new Tclass(tcId,tcno);
            }
            return t;
        }


        /// <summary>
        /// 根据班级编号修改数据
        /// </summary>
        public int update(Tclass t)
        {
            
            string sql = "update tclass set tcNo='"+t.TcNo+"' where tcId="+t.TcId;
            return DAL.DBhepter.ExecuteNonQuery(sql);
        }



        /// <summary>
        /// 根据班级编号删除数据
        /// </summary>
        public int delete(int tcid)
        {

            string sql = "delete from tclass where tcId=" +tcid;
            return DAL.DBhepter.ExecuteNonQuery(sql);
        }
    }
}